package cn.com.dashihui.api.controller;

import java.util.List;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;

import cn.com.dashihui.api.base.BaseController;
import cn.com.dashihui.api.service.AdService;

public class AdController extends BaseController{
	private AdService service = new AdService();
	
	/**
	 * 查询公共广告位
	 */
    public void publicAdList(){
		renderSuccess(service.findPublicAd());
    }
    
    /**
	 * 查询指定店铺的广告位
	 * @param STOREID 店铺ID
	 */
	public void storeAdList(){
		String storeidStr = getPara("STOREID");
		if(StrKit.isBlank(storeidStr)){
    		renderFailed("参数STOREID不能为空");
    		return;
		}else{
			int storeid = Integer.valueOf(storeidStr);
			renderSuccess(service.findStoreAd(storeid));
		}
	}
	/**
	 * 查询服务消息列表
	 */
	public void queryServiceNews() {
		List<Record> serviceNewsList=service.queryServiceNews();
		if (serviceNewsList!=null) {
			renderSuccess(serviceNewsList);
		}else {
			renderFailed();
		}
		
	}
	/**
	 * 查询系统消息列表
	 */
	public void querySystemNews() {
		String typeStr=getPara("TYPE");
		if (StrKit.isBlank(typeStr)) {
			renderFailed("网络错误");
			return;
		}
		int type=Integer.valueOf(typeStr);
		List<Record> systemNewsList=service.querySystemNews(type);
		if (systemNewsList!=null) {
			renderSuccess(systemNewsList);
		}else {
			renderFailed();
		}
	}
	/**
	 * 查询公告详情
	 */
	public void queryNewsDeatil() {
		int id=getParaToInt("id");
		renderSuccess(service.querySystemNewsDeatil(id));
	}
	
	/**
	 * 查询轮播图
	 */
	public void queryCarousel() {
		String page=getPara("PAGE");
		if (!StrKit.isBlank(page)) {
			renderSuccess(service.queryCarousel(Integer.valueOf(page)));
		}else {
			renderFailed("查询出错，参数page为空");
		}
		
	}
}
